﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.Model.Services;
using Domain.Model.Vehiculos;
using Domain.Model.Repositories;
using Domain.Model.Aggregates;

namespace Domain.Model.Entidades.Vehiculos
{
    public class VehiculoService: IVehiculoService
    {
        /// Referencia al servicio de Vehiculos
        private VehiculoRepository vehiculoRepository;


        //Constructor
        public VehiculoService(VehiculoRepository vehiculoRepository)
        {
            if (vehiculoRepository == null)
            {
                throw new ArgumentNullException("vehiculoRepository");
            }
            this.vehiculoRepository = vehiculoRepository;
        }

        public Vehiculo VehiculoFromId(string VehiculoId)
        {
            return this.vehiculoRepository.FromId(new VehiculoId(VehiculoId));
        }

        public VehiculoId CreateVehiculo(string vin, string placa, string licenciaVehiculo, string tipo, string servicio)
        {
            Vehiculo newVehiculo;

            newVehiculo = VehiculoAggregate.CreateVehiculo((VehiculoId)vehiculoRepository.NextIdentity(),vin,placa, licenciaVehiculo,tipo,servicio);

            this.vehiculoRepository.Insert(newVehiculo);

            return (VehiculoId)newVehiculo.Identity;
        }


        public List<Vehiculo> All()
        {
            return this.vehiculoRepository.All();
        }


        public void RemoveVehiculo(VehiculoId VehiculoId)
        {
            this.vehiculoRepository.Remove(VehiculoId);
        }


        public VehiculoId EditVehiculo(VehiculoId VehiculoId, string vin, string placa, string licenciaVehiculo, string tipo, string servicio)
        {
            Vehiculo newVehiculo;

            newVehiculo = VehiculoAggregate.CreateVehiculo(VehiculoId, vin, placa, licenciaVehiculo, tipo, servicio);

            this.vehiculoRepository.Update(newVehiculo);

            return (VehiculoId)newVehiculo.Identity;
        }
    }
}
